<?php include('header.php'); ?>
<!-- add new user form -->
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="GET">
Username: <input type="text" name="user"/><br>
First Name: <input type="text" name="first"/><br>
Last Name: <input type="text" name="last"/><br>
<input type="submit" value="Add New User!"/>
</form>

<?php

// get form data
$user = $db->real_escape_string($_GET['user']);
$first = $db->real_escape_string($_GET['first']);
$last = $db->real_escape_string($_GET['last']);

// build insert query
$str = "INSERT INTO people (USERNAME, FIRST_NAME, LAST_NAME) VALUES ('"
		.$user."','".$first."','".$last."')";
		
// run query
$result = $db->query($str);
echo $db->error;

// print all names in FORMATTED table
$str = "SELECT * FROM people";
$result = $db->query($str);

echo <<<EOF
<table>
<th>First Name</th>
<th>Last Name</th>
EOF;

// check for odd, even, give variable class
$i = 0;
while($row = $result->fetch_assoc()) {
	$i++;
	if ( $i%2 == 0 ) {
		$tr = "<tr class='even'>";
	} else {
		$tr = "<tr class='odd'>";
	}
	$tr = $tr . "<td>".$row["FIRST_NAME"]."</td><td>".$row["LAST_NAME"]."</td></tr>";
	echo $tr;
}
echo "</table><br><br>";
?>




<?php include('footer.php'); ?>